﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace sharpCmd.Controls.Viewers
{
    internal partial class TextViewer : ViewerControl
    {
        public TextViewer()
        {
            InitializeComponent();
            base.WordWrapChanged += new EventHandler(wordWrapChanged);
        }

        public override void Display()
        {
        }

        /// <summary>
        /// Get count of lines displayed
        /// </summary>
        private int LineCount
        {
            get
            {
                return (int)((float)this.Height / this.Font.GetHeight()) + 1;
            }
        }

        private List<string> ReadData()
        {
            //TODO if word wrap is on, do different stuff
            /*Reader.BaseStream.Seek(Position, SeekOrigin.Begin);
            string[] lines = new string[LineCount];
            for(int i = 0; i < 
            return null;*/
            //for now, read to end
            Reader.BaseStream.Seek(Position, SeekOrigin.Begin);
            List<string> lines = new List<string>();
            string line;
            while ((line = Reader.ReadLine()) != null)
                lines.Add(line);
            return lines;
        }

        private void TextViewer_Paint(object sender, PaintEventArgs e)
        {
            //read required data from file
            var lines = ReadData();
            //draw clip rect
            //TODO vertical scrolling at least

            for (int i = 0; i < LineCount; i++)
            {
                if (i >= lines.Count)
                    break;
                e.Graphics.DrawString(lines[i], ViewerStatic.MonospaceFont, Brushes.Black, 0, this.Font.GetHeight() * i);
            }
        }

        private void wordWrapChanged(object sender, EventArgs e)
        {

        }
    }
}
